home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 44 / PC Actual CD 44.iso / Linux / Cygwin / full.exe / Disk1 / data1.cab / Tools / share / tix4.1 / Primitiv.tcl < prev    next >
Encoding:
Text File  |  1998-12-04  |  10.0 KB  |  426 lines

  1. # Primitiv.tcl --
  2. #
  3. #    This is the primitive widget. It is just a frame with proper
  4. #    inheritance wrapping. All new Tix widgets will be derived from
  5. #    this widget
  6. #
  7. # Copyright (c) 1996, Expert Interface Technologies
  8. #
  9. # See the file "license.terms" for information on usage and redistribution
  10. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. #
  12.  
  13.  
  14.  
  15. # No superclass, so the superclass switch is not used
  16. #
  17. #
  18. tixWidgetClass tixPrimitive {
  19.     -virtual true
  20.     -superclass {}
  21.     -classname  TixPrimitive
  22.     -method {
  23.     cget configure subwidget subwidgets
  24.     }
  25.     -flag {
  26.     -background -borderwidth -cursor
  27.     -height -highlightbackground -highlightcolor -highlightthickness
  28.     -options -relief -takefocus -width -bd -bg
  29.     }
  30.     -static {
  31.     -options
  32.     }
  33.     -configspec {
  34.     {-background background Background #d9d9d9} 
  35.     {-borderwidth borderWidth BorderWidth 0} 
  36.     {-cursor cursor Cursor ""} 
  37.     {-height height Height 0}
  38.     {-highlightbackground highlightBackground HighlightBackground #c3c3c3}
  39.     {-highlightcolor highlightColor HighlightColor black}
  40.     {-highlightthickness highlightThickness HighlightThickness 0} 
  41.     {-options options Options ""}
  42.     {-relief relief Relief flat}
  43.     {-takefocus takeFocus TakeFocus 0 tixVerifyBoolean} 
  44.     {-width width Width 0}
  45.     }
  46.     -alias {
  47.     {-bd -borderwidth}
  48.     {-bg -background}
  49.     }
  50. }
  51.  
  52. #----------------------------------------------------------------------
  53. # ClassInitialization:
  54. #----------------------------------------------------------------------
  55.  
  56. # not used
  57. # Implemented in C
  58. #
  59. # Override: never
  60. proc tixPrimitive:Constructor {w args} {
  61.  
  62.     upvar #0 $w data
  63.     upvar #0 $data(className) classRec
  64.  
  65.     # Set up some minimal items in the class record.
  66.     #
  67.     set data(w:root)  $w
  68.     set data(rootCmd) $w:root
  69.  
  70.     # We need to create the root widget in order to parse the options
  71.     # database
  72.     tixCallMethod $w CreateRootWidget
  73.  
  74.     # Parse the default options from the options database
  75.     #
  76.     tixPrimitive:ParseDefaultOptions $w
  77.  
  78.     # Parse the options supplied by the user
  79.     #
  80.     tixPrimitive:ParseUserOptions $w $args
  81.  
  82.     # Rename the widget command so that it can be use to access
  83.     # the methods of this class
  84.  
  85.     tixPrimitive:MkWidgetCmd $w
  86.  
  87.     # Inistalize the Widget Record
  88.     #
  89.     tixCallMethod $w InitWidgetRec
  90.  
  91.     # Construct the compound widget
  92.     #
  93.     tixCallMethod $w ConstructWidget
  94.  
  95.     # Do the bindings
  96.     #
  97.     tixCallMethod $w SetBindings
  98.  
  99.     # Call the configuration methods for all "force call" options
  100.     #
  101.     foreach option $classRec(forceCall) {
  102.     tixInt_ChangeOptions $w $option $data($option)
  103.     }
  104. }
  105.  
  106.  
  107. # Create only the root widget. We need the root widget to query the option
  108. # database.
  109. #
  110. # Override: seldom. (unless you want to use a toplevel as root widget)
  111. # Chain   : never.
  112.  
  113. proc tixPrimitive:CreateRootWidget {w args} {
  114.     upvar #0 $w data
  115.     upvar #0 $data(className) classRec
  116.  
  117.     frame $w -class $data(ClassName)
  118. }
  119.  
  120. proc tixPrimitive:ParseDefaultOptions {w} {
  121.     upvar #0 $w data
  122.     upvar #0 $data(className) classRec
  123.  
  124.     # SET UP THE INSTANCE RECORD ACCORDING TO DEFAULT VALUES IN
  125.     # THE OPTIONS DATABASE
  126.     #
  127.     foreach option $classRec(options) {
  128.     set spec [tixInt_GetOptionSpec $data(className) $option]
  129.  
  130.     if {[lindex $spec 0] == "="} {
  131.         continue
  132.     }
  133.  
  134.     set o_name    [lindex $spec 1]
  135.     set o_class   [lindex $spec 2]
  136.     set o_default [lindex $spec 3]
  137.  
  138.     if {![catch "option get $w $o_name $o_class" db_default]} {
  139.         if {$db_default != ""} {
  140.         set data($option) $db_default
  141.         } else {
  142.         set data($option) $o_default
  143.         }
  144.     } else {
  145.         set data($option) $o_default
  146.     }
  147.     }
  148. }
  149.  
  150. proc tixPrimitive:ParseUserOptions {w arglist} {
  151.     upvar #0 $w data
  152.     upvar #0 $data(className) classRec
  153.  
  154.     # SET UP THE INSTANCE RECORD ACCORDING TO COMMAND ARGUMENTS FROM
  155.     # THE USER OF THE TIX LIBRARY (i.e. Application programmer:)
  156.     #
  157.     tixForEach {option arg} $arglist {
  158.     if {[lsearch $classRec(options) $option] != "-1"} {
  159.         set spec [tixInt_GetOptionSpec $data(className) $option]
  160.  
  161.         if {[lindex $spec 0] != "="} {
  162.         set data($option) $arg
  163.         } else {
  164.         set realOption [lindex $spec 1]
  165.         set data($realOption) $arg
  166.         }
  167.     } else {
  168.         error "unknown option $option. Should be: [tixInt_ListOptions $w]"
  169.     }
  170.     }
  171. }
  172.  
  173. #----------------------------------------------------------------------
  174. # Initialize the widget record
  175. #
  176. # Override: always
  177. # Chain   : always, before
  178. proc tixPrimitive:InitWidgetRec {w} {
  179.     # default: do nothing
  180. }
  181.  
  182. #----------------------------------------------------------------------
  183. # SetBindings
  184. #
  185. # Override: sometimes
  186. # Chain   : sometimes, before
  187. #
  188. bind TixDestroyHandler <Destroy> {
  189.     [tixGetMethod %W [set %W(className)] Destructor] %W
  190. }
  191.  
  192. proc tixPrimitive:SetBindings {w} {
  193.     upvar #0 $w data
  194.  
  195.     if {[winfo toplevel $w] == $w} {
  196.     bindtags $w [concat TixDestroyHandler [bindtags $w]]
  197.     } else {
  198.     bind $data(w:root) <Destroy> \
  199.         "[tixGetMethod $w $data(className) Destructor] $w"
  200.     }
  201. }
  202.  
  203. #----------------------------------------------------------------------
  204. # PrivateMethod: ConstructWidget
  205. # Construct and set up the compound widget
  206. #
  207. # Override: sometimes
  208. # Chain   : sometimes, before
  209. #
  210. proc tixPrimitive:ConstructWidget {w} {
  211.     upvar #0 $w data
  212.  
  213.     $data(rootCmd) config \
  214.     -background  $data(-background) \
  215.     -borderwidth $data(-borderwidth) \
  216.     -cursor      $data(-cursor) \
  217.     -relief      $data(-relief)
  218.  
  219.     if {$data(-width) != 0} {
  220.     $data(rootCmd) config -width $data(-width)
  221.     }
  222.     if {$data(-height) != 0} {
  223.     $data(rootCmd) config -height $data(-height)
  224.     }
  225.  
  226.     set rootname *[string range $w 1 end]
  227.  
  228.     tixForEach {spec value} $data(-options) {
  229.     option add $rootname*$spec $value 100
  230.     }
  231. }
  232.  
  233. #----------------------------------------------------------------------
  234. # PrivateMethod: MkWidgetCmd
  235. # Construct and set up the compound widget
  236. #
  237. # Override: sometimes
  238. # Chain   : sometimes, before
  239. #
  240. proc tixPrimitive:MkWidgetCmd {w} {
  241.     upvar #0 $w data
  242.  
  243.     rename $w $data(rootCmd)
  244.     tixInt_MkInstanceCmd $w
  245. }
  246.  
  247.  
  248. #----------------------------------------------------------------------
  249. # ConfigOptions:
  250. #----------------------------------------------------------------------
  251.  
  252. #----------------------------------------------------------------------
  253. # ConfigMethod: config
  254. #
  255. # Configure one option.
  256. # Override: always
  257. # Chain   : automatic.
  258. #
  259. # Note the hack of [winfo width] in this procedure
  260. #
  261. # The hack is necessary because of the bad interaction between TK's geometry
  262. # manager (the packer) and the frame widget. The packer determines the size
  263. # of the root widget of the ComboBox (a frame widget) according to the
  264. # requirement of the slaves inside the frame widget, NOT the -width
  265. # option of the frame widget.
  266. #
  267. # However, everytime the frame widget is
  268. # configured, it sends a geometry request to the packer according to its
  269. # -width and -height options and the packer will temporarily resize
  270. # the frame widget according to the requested size! The packer then realizes
  271. # something is wrong and revert to the size determined by the slaves. This
  272. # cause a flash on the screen.
  273. #
  274. foreach opt {-height -width -background -borderwidth -cursor
  275.         -highlightbackground -highlightcolor -relief -takefocus -bd -bg} {
  276.  
  277.     set tixPrimOpt($opt) 1
  278. }
  279.  
  280. proc tixPrimitive:config {w option value} {
  281.     global tixPrimOpt
  282.     upvar #0 $w data
  283.  
  284.     if [info exists tixPrimOpt($option)] {
  285.     $data(rootCmd) config $option $value
  286.     }
  287. }
  288.  
  289. #----------------------------------------------------------------------
  290. # PublicMethods:
  291. #----------------------------------------------------------------------
  292.  
  293. #----------------------------------------------------------------------
  294. # This method is used to implement the "subwidgets" widget command.
  295. # Will be re-written in C. It can't be used as a public method because
  296. # of the lame substring comparison routines used in tixClass.c
  297. #
  298. #
  299. proc tixPrimitive:subwidgets {w type args} {
  300.     upvar #0 $w data
  301.  
  302.     case $type {
  303.     -class {
  304.         set name [lindex $args 0]
  305.         set args [lrange $args 1 end]
  306.         # access subwidgets of a particular class
  307.         #
  308.         # note: if $name=="Frame", will *not return the root widget as well
  309.         #
  310.         set sub ""
  311.         foreach des [tixDescendants $w] {
  312.         if {[winfo class $des] == $name} {
  313.             lappend sub $des
  314.         }
  315.         }
  316.  
  317.         # Note: if the there is no subwidget of this class, does not
  318.         # cause any error.
  319.         #
  320.         if {$args == ""} {
  321.         return $sub
  322.         } else {
  323.         foreach des $sub {
  324.             eval $des $args
  325.         }
  326.         return ""
  327.         }
  328.     }
  329.     -group {
  330.         set name [lindex $args 0]
  331.         set args [lrange $args 1 end]
  332.         # access subwidgets of a particular group
  333.         #
  334.         if [info exists data(g:$name)] {
  335.         if {$args == ""} {
  336.             set ret ""
  337.             foreach item $data(g:$name) {
  338.             lappend ret $w.$item
  339.             }
  340.             return $ret
  341.         } else {
  342.             foreach item $data(g:$name) {
  343.             eval $w.$item $args
  344.             }
  345.             return ""
  346.         }
  347.         } else {
  348.         error "no such subwidget group $name"
  349.         }
  350.     }
  351.     -all {
  352.         set sub [tixDescendants $w]
  353.  
  354.         if {$args == ""} {
  355.         return $sub
  356.         } else {
  357.         foreach des $sub {
  358.             eval $des $args
  359.         }
  360.         return ""
  361.         }
  362.     }
  363.     default {
  364.         error "unknown flag $type, should be -all, -class or -group"
  365.     }
  366.     }
  367. }
  368.  
  369. #----------------------------------------------------------------------
  370. # PublicMethod: subwidget
  371. #
  372. # Access a subwidget withe a particular name 
  373. #
  374. # Override: never
  375. # Chain   : never
  376. #
  377. proc tixPrimitive:subwidget {w name args} {
  378.     upvar #0 $w data
  379.  
  380.     if [info exists data(w:$name)] {
  381.     if {$args == ""} {
  382.         return $data(w:$name)
  383.     } else {
  384.         return [eval $data(w:$name) $args]
  385.     }
  386.     } else {
  387.     error "no such subwidget $name"
  388.     }
  389. }
  390.  
  391.  
  392. #----------------------------------------------------------------------
  393. # PrivateMethods:
  394. #----------------------------------------------------------------------
  395.  
  396. # delete the widget record and remove the command
  397. #
  398. proc tixPrimitive:Destructor {w} {
  399.     upvar #0 $w data
  400.  
  401.     if {![info exists data(w:root)]} {
  402.     return
  403.     }
  404.  
  405.     if {[info commands $w] != ""} {
  406.     # remove the command
  407.     #
  408.     rename $w ""
  409.     }
  410.  
  411.     if {[info commands $data(rootCmd)] != ""} {
  412.     # remove the command of the root widget
  413.     #
  414.     rename $data(rootCmd) ""
  415.     }
  416.  
  417.     # delete the widget record
  418.     #
  419.     catch {unset data}
  420. }
  421.